package cn.iocoder.yudao.module.handguard.controller.app.usertablesaudit;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.handguard.controller.app.user.vo.TransferWarrantReqVo;
import cn.iocoder.yudao.module.handguard.controller.app.usertablesaudit.vo.*;
import cn.iocoder.yudao.module.handguard.convert.usertablesaudit.UserTablesAuditConvert;
import cn.iocoder.yudao.module.handguard.dal.dataobject.usertablesaudit.UserTablesAuditDO;
import cn.iocoder.yudao.module.handguard.service.user.MiniUserService;
import cn.iocoder.yudao.module.handguard.service.usertablesaudit.UserTablesAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUser;

@Tag(name = "小程序 - 用户-完善资料记录")
@RestController
@RequestMapping("/hutai/user-tables-audit")
@Validated
public class UserTablesAuditController {

    @Resource
    private UserTablesAuditService userTablesAuditService;

    @Resource
    private MiniUserService miniUserService;

    @PostMapping("/create")
    @Operation(summary = "业务员-完善资料保存")
    public CommonResult<String> createUserTablesAudit(@Valid @RequestBody UserTablesAuditCreateReqsVO createReqVO) {
        return success(userTablesAuditService.createUserTablesAudit(createReqVO));
    }

    @PostMapping("/update")
    @Operation(summary = "完善资料驳回-业务员重新提交")
    public CommonResult<Boolean> updateUserTablesAudit(@Valid @RequestBody UserTablesAuditUpdateReqsVO updateReqVO) {
        userTablesAuditService.updateUserTablesAudits(updateReqVO);
        return success(true);
    }

    @PostMapping("/data/transfer-warrant")
    @Operation(summary = "业务员-订单转权证")
    public CommonResult<String> transferWarrant(@Valid @RequestBody TransferWarrantReqVo reqsVo) {
        //当前用户id
        Long userId = getLoginUser().getId();
        reqsVo.setUserId(userId);
        return miniUserService.transferWarrant(reqsVo);
    }

    @PutMapping("/data/verify")
    @Operation(summary = "权证-资料审核-更新资料记录")
    public CommonResult<Boolean> updateUserTablesAudit(@Valid @RequestBody UserTablesAuditUpdateReqVO updateReqVO) {
        userTablesAuditService.updateUserTablesAudit(updateReqVO);
        return success(true);
    }

    @PostMapping("/agent/reject")
    @Operation(summary = "业务员-资料审核-驳回")
    public CommonResult<Boolean> updateApplicationAudit(@Valid @RequestBody UserAuditUpdateReqVO updateReqVO) {
        userTablesAuditService.updateApplicationAudit(updateReqVO);
        return success(true);
    }


    @GetMapping("/list")
    @Operation(summary = "根据订单ID公示表名称-获取资料记录数据")
    @Parameter(name = "orderId", description = "订单ID", required = true, example = "1024")
    @Parameter(name = "typeName", description = "公示表名称", required = true, example = "完成保单贷公式表")
    public CommonResult<List<UserTablesAuditRespVO>> getUserTablesAuditList(@RequestParam("orderId") Long orderId, @RequestParam("typeName") String typeName) {
        List<UserTablesAuditDO> list = userTablesAuditService.getUserTablesAuditList(orderId,typeName);
        return success(UserTablesAuditConvert.INSTANCE.convertList(list));
    }


//    @DeleteMapping("/delete")
//    @Operation(summary = "删除用户-完善资料记录")
//    @Parameter(name = "id", description = "编号", required = true)
//    @PreAuthorize("@ss.hasPermission('hutai:user-tables-audit:delete')")
//    public CommonResult<Boolean> deleteUserTablesAudit(@RequestParam("id") Long id) {
//        userTablesAuditService.deleteUserTablesAudit(id);
//        return success(true);
//    }

//    @GetMapping("/get")
//    @Operation(summary = "获得用户-完善资料记录")
//    @Parameter(name = "id", description = "编号", required = true, example = "1024")
//    @PreAuthorize("@ss.hasPermission('hutai:user-tables-audit:query')")
//    public CommonResult<UserTablesAuditRespVO> getUserTablesAudit(@RequestParam("id") Long id) {
//        UserTablesAuditDO userTablesAudit = userTablesAuditService.getUserTablesAudit(id);
//        return success(UserTablesAuditConvert.INSTANCE.convert(userTablesAudit));
//    }

//    @GetMapping("/list")
//    @Operation(summary = "根据订单ID 获得用户-完善资料记录数据集合")
//    @Parameter(name = "orderId", description = "订单ID", required = true, example = "1024")
//    public CommonResult<List<UserTablesAuditRespVO>> getUserTablesAuditList(@RequestParam("orderId") Long orderId) {
//        List<UserTablesAuditDO> list = userTablesAuditService.getUserTablesAuditList(orderId);
//        return success(UserTablesAuditConvert.INSTANCE.convertList(list));
//    }

//    @GetMapping("/page")
//    @Operation(summary = "获得用户-完善资料记录分页")
//    @PreAuthorize("@ss.hasPermission('hutai:user-tables-audit:query')")
//    public CommonResult<PageResult<UserTablesAuditRespVO>> getUserTablesAuditPage(@Valid UserTablesAuditPageReqVO pageVO) {
//        PageResult<UserTablesAuditDO> pageResult = userTablesAuditService.getUserTablesAuditPage(pageVO);
//        return success(UserTablesAuditConvert.INSTANCE.convertPage(pageResult));
//    }
//
//    @GetMapping("/export-excel")
//    @Operation(summary = "导出用户-完善资料记录 Excel")
//    @PreAuthorize("@ss.hasPermission('hutai:user-tables-audit:export')")
//    @OperateLog(type = EXPORT)
//    public void exportUserTablesAuditExcel(@Valid UserTablesAuditExportReqVO exportReqVO,
//              HttpServletResponse response) throws IOException {
//        List<UserTablesAuditDO> list = userTablesAuditService.getUserTablesAuditList(exportReqVO);
//        // 导出 Excel
//        List<UserTablesAuditExcelVO> datas = UserTablesAuditConvert.INSTANCE.convertList02(list);
//        ExcelUtils.write(response, "用户-完善资料记录.xls", "数据", UserTablesAuditExcelVO.class, datas);
//    }

}
